<?php

class CI_Curl {

    private $_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";

    public function __construct() {

    }

    public function getAgent() {
        return $this->_agent;
    }

    public function setAgent($agent) {
        $this->_agent = $agent;
    }

    private function _openCurl() {
        return curl_init();
    }

    private function _setOption($ch, $url) {
        curl_setopt($ch, CURLOPT_USERAGENT, $this->_agent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
    }

    private function _setPostOption($ch, $fields=array()) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
    }

    private function _exec($ch) {
        return curl_exec($ch);
    }

    public function get($url) {
        $ch = $this->_openCurl();
        $this->_setOption($ch, $url);
        $get = $this->_exec($ch);
        curl_close($ch);
        return $get;
    }

    public function post($url, $postFields=array()) {
        $ch = $this->_openCurl();
        $this->_setOption($ch, $url);
        $this->_setPostOption($ch, $postFields);
        $post = $this->_exec($ch);
        curl_close($ch);
        return $post;
    }

}

?>